﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Script.Serialization;
using System.Data.SqlClient;

namespace WineDAL
{
    public class WineDetailsDAL
    {
        SQLHelper helper = new SQLHelper();

        /// <summary>
        /// 根据编号显示商品信息
        /// </summary>
        /// <param name="GID"></param>
        /// <returns></returns>
        public ArrayList Details_Show(int GID)
        {
            SqlParameter par = new SqlParameter("@GID", GID);
            DataTable table = helper.ExecDataTable_Proc("Details_Show", par);
            //JavaScriptSerializer jss = new JavaScriptSerializer();
            System.Collections.ArrayList dic = new System.Collections.ArrayList();
            foreach (DataRow dr in table.Rows)
            {
                System.Collections.Generic.Dictionary<string, object> drow = new System.Collections.Generic.Dictionary<string, object>();
                foreach (DataColumn dc in table.Columns)
                {
                    drow.Add(dc.ColumnName, dr[dc.ColumnName]);
                }
                dic.Add(drow);
            }
            return dic;
        }
        /// <summary>
        /// 根据商品编号显示商品评论
        /// </summary>
        /// <param name="GID"></param>
        /// <returns></returns>
        public ArrayList Comments_Show(int GID)
        {
            SqlParameter par = new SqlParameter("@id", GID);
            DataTable table = helper.ExecDataTable_Proc("Comment_Show", par);
            JavaScriptSerializer jss = new JavaScriptSerializer();
            System.Collections.ArrayList dic = new System.Collections.ArrayList();
            foreach (DataRow dr in table.Rows)
            {
                System.Collections.Generic.Dictionary<string, object> drow = new System.Collections.Generic.Dictionary<string, object>();
                foreach (DataColumn dc in table.Columns)
                {
                    drow.Add(dc.ColumnName, dr[dc.ColumnName]);
                }
                dic.Add(drow);
            }
            return dic;
        }
        /// <summary>
        /// 添加购物车
        /// </summary>
        /// <param name="shop"></param>
        /// <returns></returns>
        public int ShopAddDo(WineModel.Shop shop)
        {
            SqlParameter[] par = { new SqlParameter("@GoodsID", shop.GoodsID), new SqlParameter("@UsersID", shop.UsersID), new SqlParameter("@ShopDate", shop.ShopDate), new SqlParameter("@GoodsPrice", shop.GoodsPrice), new SqlParameter("@GoodsNum", shop.GoodsNum) };
            return helper.ExecNonquery_Proc("ShopAdd", par);
        }
    }
}
